#include <Arduino.h>
#include "mtime.h"
#include "config.h"
#include "animations.h"

static const long gmtOffset_sec = 8 * 3600; // 时区偏移量，北京是GMT+8
static const int daylightOffset_sec = 0;    // 夏令时偏移量，中国无夏令时
void sync_sys_time()
{
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServerUrl3, ntpServerUrl2, ntpServerUrl1);

  Serial.print(F("Waiting for NTP time sync: "));
  time_t nowSecs = time(nullptr);
  while (nowSecs < 8 * 3600 * 2)
  {
    delay(500);
    Serial.print(F("."));
    yield();
    nowSecs = time(nullptr);
    time_sync_anim_v2();
  }

  Serial.println();
  print_local_time();
}

void print_local_time()
{
  struct tm timeinfo;
  if (!getLocalTime(&timeinfo))
  {
    Serial.println("Failed to obtain time");
    return;
  }
  Serial.print(F("Current Local time: "));
  //  Serial.println(&timeinfo, "%F %T %A");
  Serial.print(asctime(&timeinfo));
}
